package com.easy.easybanner;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.easy.easybanner.view.EasyBannerView;
import com.easy.easybanner.view.EasyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private EasyBannerView mEasyBannerView;
    private List<TestBean> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
        initData();
    }

    private void initData() {
        for(int x=0;x<5;x++){
            TestBean testBean=new TestBean();
            testBean.setImagePath("http://www.baidu.com/img/bd_logo1.png");
            testBean.setTitle("标题"+(x+1));
            list.add(testBean);
        }
        initBanner();
    }

    private void initBanner() {
        mEasyBannerView.setEasyPagerAdapter(new EasyPagerAdapter() {
            @Override
            protected View getView(int position,View convertView) {
                ImageView imageView=null;
                if(convertView==null){
                    imageView=new ImageView(MainActivity.this);
                }else{
                    imageView= (ImageView) convertView;
                }
                Glide.with(MainActivity.this).load(list.get(position).getImagePath()).into(imageView);
                return imageView;
            }

            @Override
            protected int getIndicatorSize() {
                return list.size();
            }

            @Override
            public void setTitle(TextView mTvTitle, int mCurrentPosition) {
                mTvTitle.setText(list.get(mCurrentPosition).getTitle());
            }

            @Override
            public int getCount() {
                return list.size();
            }
        });
        mEasyBannerView.setAutomaticRolling();
    }

    private void initview() {
        mEasyBannerView = (EasyBannerView) findViewById(R.id.easy_banner_view);
        findViewById(R.id.but_test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
            }
        });
    }
}
